package com.gt.quality.system.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gt.quality.config.SpringBeanUtil;
import com.gt.quality.system.entity.SysRoleDept;
import com.gt.quality.system.mapper.SysRoleDeptMapper;
import com.gt.quality.base.pojo.BaseLimitRequest;
import com.gt.quality.base.pojo.LayerListViewObject;
import com.gt.quality.system.service.SysDeptService;
import com.gt.quality.system.service.SysRoleDeptService;
import jakarta.annotation.Resource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;

import java.util.List;

/**
 * 角色和部门关联表(SysRoleDept)表服务实现类
 *
 * @author makejava
 * @since 2026-11-25 16:30:08
 */
@Service("sysRoleDeptService")
public class SysRoleDeptServiceImpl extends ServiceImpl<SysRoleDeptMapper, SysRoleDept> implements SysRoleDeptService {

    @Resource
    private SysRoleDeptMapper sysRoleDeptMapper;

    @Resource
    private SysDeptService sysDeptService;

    /**
     * Description:  分页查询
     *
     * @param limitRequest 分页查询参数
     * @author: makeJava
     * @date: 2026-02-02 14:57:06
     * @return:com.baomidou.mybatisplus.core.metadata.IPage
     */
    @Override
    public IPage<SysRoleDept> queryLimitPage(BaseLimitRequest<SysRoleDept> limitRequest) {
        SysRoleDept requestBody = limitRequest.getRequestBody();
        IPage<SysRoleDept> page = getByPageParam(limitRequest);
        JSONObject thisObj = JSONObject.from(requestBody);
        QueryWrapper<SysRoleDept> queryWrapper = queryWrapperBuilder(thisObj, limitRequest);
        return sysRoleDeptMapper.selectPage(page, queryWrapper);
    }

      /**
     * Description:  批量新增优化版
     *
     * @param entityList entityList
     * @author: makeJava
     * @date: 2026-02-02 19:54:59

     */
    @Override
    public Integer saveBatchByEasyBaseMapper(List<SysRoleDept> entityList) {

        return sysRoleDeptMapper.insertBatchSomeColumn(entityList);
    }

    @Override
    public LayerListViewObject buildTreeDeptInfo(Long roleId) {
        LayerListViewObject viewObject = sysDeptService.buildTree();
        if (roleId != null) {
            List<Long> thisMenu = sysDeptService.selectDeptIdsByRoleId(roleId);
            viewObject.setCurrentLayer(thisMenu);
        }
        return viewObject;
    }



    /**
     * 往上传递 SqlSessionFactory
     * @return SqlSessionFactory
     */
    @Override
    public SqlSessionFactory getSqlSessionFactory() {
        return super.getSqlSessionFactory();
    }

    /**
     * 往上传递 Mapper
     * @return Mapper
     */
    @Override
    public Class<?> getThisMapperClass() {
        return SysRoleDeptMapper.class;
    }

    /**
     * 往上传递 Transaction
     * @return Transaction
     */
    @Override
    public TransactionTemplate getSpringTx() {
        return SpringBeanUtil.getBean(TransactionTemplate.class);
    }
}


